layui.use('form', function () {
    var form = layui.form
        ,layer = layui.layer;
});
// 定义注册组件
const regist_component = {
    template: '#register',
    data() {
        return {
            form: {
                username: '',
                password: ''
            }
        }
    },
    methods: {
        onSubmit() {
            var vm = this;
            var username = vm.form.username;
            var userpwd = vm.form.password;
            if (username.length===0) {
                layer.tips("用户名不能为空，请输入", '#username', {
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                $("#username").focus();
                return false;
            }
            if (userpwd.length===0) {
                layer.tips("请输入密码",'#password',{
                    tips: [1, "#0FA6D8"],
                    tipsMore: !1,
                    time: 2000
                });
                $("#password").focus();
                return false;
            }

            let params = {"username":username ,"userpassword":userpwd};

            axios.post('/register',
                params
            ).then(function(response) {
                console.log(response);
                if(response.data.code=='200'){
                    layer.msg(response.data.message, {
                        time: 1000,
                        icon: 1,
                        offset: '350px'
                    }, function () {
                        location.href="/";
                    });

                }else{
                    layer.msg(response.data.message, {
                        time: 1500,
                        icon: 2,
                        offset: '350px'
                    });
                }
            }).catch(function(error) {
                console.log(error);
            });
        }

    }
};
//定义路由
const routes = [{
    path: '/',
    component: regist_component
}]

// 创建 router 实例
const routerInstance = new VueRouter({
    routes: routes
});

// 创建 Vue 实例  并注册路由
var vm = new Vue({
    el: '#app',
    router : routerInstance
})